/**********************\
* Code: Dzlua
* QQ:505544956
* Time:2017/05/17
\**********************/
#ifndef __COMMON_H__
#define __COMMON_H__
#pragma once

#include <string>
#include <vector>

#ifdef ShellExecute
    #define COMMON_SHELLEXECUTE ShellExecute
    #undef ShellExecute
#endif

class Common {
public:
    // run cmd
    static bool ExecuteShell(const std::string& exe, const std::string& param, bool wait = false);
    static bool ExecuteShell(const std::wstring& exe, const std::wstring& param, bool wait = false);
    /* if file not exist, return empty.*/
    static std::string GetShortPath(const std::string& file);
    static std::wstring GetShortPath(const std::wstring& file);
    /* place the give str at begin and end of src 
        src:"aaa",str:"."->".aaa."
    */
    static std::string AroundMarks(const std::string& str, const std::string& mark);
    static std::wstring AroundMarks(const std::wstring& str, const std::wstring& mark);

    // split the string s with c,save them the result at v.
    static void Split(const std::string& s, std::vector<std::string>& v, const std::string& c);
    static void Split(const std::wstring& s, std::vector<std::wstring>& v, const std::wstring& c);

    static std::string UnSplit(std::vector<std::string>& v, const std::string& c);
    static std::wstring UnSplit(std::vector<std::wstring>& v, const std::wstring& c);

    // erase the space of begin and end.
    static std::string Trim(const std::string& s);
    static std::wstring Trim(const std::wstring& s);

    // base64
    static std::string Base64Encode(const std::string& input);
    static std::wstring Base64Encode(const std::wstring& input);
    static std::string Base64Decode(const std::string& input);
    static std::wstring Base64Decode(const std::wstring& input);

    //file
    static std::string ReadFile(const std::string& input);
    static std::wstring ReadFile(const std::wstring& input);
    static bool WriteFile(const std::string& input, const std::string& con);
    static bool WriteFile(const std::wstring& input, const std::wstring& con);

    //
    enum encode_t {
        utf8 = 0,
        win_sys,
    };
    static std::wstring	str2wstr(const std::string& from, encode_t char_code = encode_t::win_sys);
    static std::string	wstr2str(const std::wstring& from, encode_t char_code = encode_t::win_sys);
};

#endif //__COMMON_H__